package pers.qianyu.module.system.controller;


import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import pers.qianyu.module.core.comm.*;
import pers.qianyu.module.core.domain.system.dto.*;
import pers.qianyu.module.core.domain.system.query.*;
import pers.qianyu.module.core.domain.system.vo.*;
import pers.qianyu.module.system.service.*;

/**
 * @author mizzle rain
 * @date 2020-11-13 12:25
 */
@Api(tags = "系统角色相关接口")
@RestController
@RequestMapping("/system-serv")
public class SysRoleController {
    private final SysRoleService sysRoleService;

    public SysRoleController(SysRoleService userService) {
        this.sysRoleService = userService;
    }

    @ApiOperation("根据角色id查询角色信息")
    @GetMapping("/role/{id}")
    public HttpResult<SysRoleVO> queryById(@PathVariable Long id) {
        SysRoleVO sysRoleVO = sysRoleService.queryById(id);
        return HttpResult.okWithData(sysRoleVO);
    }

    @ApiOperation("新增角色")
    @PostMapping("/role")
    public HttpResult<?> insert(@RequestBody SysRoleDTO sysRoleDTO) {
        sysRoleService.insRole(sysRoleDTO);
        return HttpResult.okWithMessage("新增角色成功");
    }

    @ApiOperation("根据id删除角色")
    @DeleteMapping("/role/{id}")
    public HttpResult<?> delete(@PathVariable Long id) {
        sysRoleService.delById(id);
        return HttpResult.okWithMessage("删除角色成功");
    }

    @ApiOperation("根据id修改角色")
    @PutMapping("/role/{id}")
    public HttpResult<?> updateById(@PathVariable Long id,
                                    @RequestBody SysRoleDTO sysRoleDTO) {
        sysRoleService.updRole(id, sysRoleDTO);
        return HttpResult.okWithMessage("角色更新成功");
    }

    @ApiOperation("批量查询角色")
    @GetMapping("/roles")
    public HttpResult<Pagination<SysRoleVO>> query(SysRoleQuery sysRoleQuery) {
        Pagination<SysRoleVO> page = sysRoleService.queryRole(sysRoleQuery);
        return HttpResult.okWithData(page);
    }
}
